<?php

class Bill_Finder_Decorator_Organiz extends Bill_Finder_Decorator {

	public function prepend ($request) {

		parent::prepend($request);

		if ($organiz = $request['organiz']) {
			
			$this->select()->where(
			"
				bh.organiz_id in ( $organiz ) 
					or 
				bh.organiz_id in ( select id from organiz where id_up in ($organiz) and type in (1,9) and 0 < id_up )
					or 
				bh.organiz_id in ( select id from organiz where id_up in ( select id from organiz where id_up in ($organiz)) and type in (1,9) and 0 < id_up )
					or 
				bh.organiz_id in ( select id from organiz where id_up in ( select id from organiz where id_up in ( select id from organiz where id_up in ($organiz))) and type in (1,9) and 0 < id_up ) 
			");

			$this->select()->distinct();
		}
		
		return $this;
	}

}